package app.sevenc.lib_framework.databind

import android.widget.ImageView
import androidx.databinding.BindingAdapter
import app.sevenc.lib_framework.imageloader.ImageLoaderProxy
import app.sevenc.lib_framework.imageloader.ScaleType

/**
 * ImageView BindingAdapter的使用
 *
 * @author Seven-C
 * @date 2021/8/7
 */
@BindingAdapter(
    value = ["imageFromUrl", "scaleType", "isCircle", "roundingRadiusPx",
        "topLeft", "topRight", "bottomRight", "bottomLeft"],
    requireAll = false
)
fun ImageView.bindImageFromUrl(
    imageUrl: String?,
    scaleType: ScaleType = ScaleType.CENTER_CROP,
    isCircle: Boolean = false,
    roundingRadiusPx: Int = 0,
    topLeft: Float = 0f,
    topRight: Float = 0f,
    bottomRight: Float = 0f,
    bottomLeft: Float = 0f
) {
    if (!imageUrl.isNullOrEmpty()) {
        ImageLoaderProxy.loadImage(
            this,
            imageUrl,
            scaleType,
            isCircle,
            roundingRadiusPx,
            topLeft,
            topRight,
            bottomRight,
            bottomLeft
        )
    }
}